<template>
	<view class="main">
		<view class="user">
			<view class="userinfo">
				<view class="userinfo_top">
					<image class="userinfo_top_img"
						:src="userinfo.avatar?userinfo.avatar:'http://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/default-avatar.png'">
					</image>
					<text v-if="type == 1">{{userinfo.nickName?userinfo.nickName:'先生'}}</text>
					<text
						v-else>{{userinfo.nickName?userinfo.nickName.charAt(0):''}}{{userinfo.gender==1?'先生':userinfo.gender==2?'女士':'先生'}}</text>
				</view>
				<view class="userinfo_top_right" @click="gotoUser()">
					<u-icon v-if="type==1" class="userinfo_top_right_icon" :label="item" name="arrow-right" size="18"
						label-pos="left" space="5"></u-icon>
				</view>
			</view>
			<view class="userinfo_center">
				<view class="userinfo_center_item">
					<view class="userlefttext">姓名</view>
					<view v-if="type == 1">{{userinfo.nickName?userinfo.nickName:'未填写'}}</view>
					<view v-else>
						{{userinfo.nickName?userinfo.nickName.charAt(0):''}}{{userinfo.gender==1?'先生':userinfo.gender==2?'女士':'先生'}}
					</view>
				</view>
				<u-line></u-line>
				<view class="userinfo_center_item">
					<view class="userlefttext">性别</view>
					<view>{{userinfo.gender?(userinfo.gender==1?'男':'女'):'男'}}</view>
				</view>
				<u-line></u-line>
				<view class="userinfo_center_item">
					<view class="userlefttext">电话</view>
					<view v-if="type == 1" style="#424242">{{userinfo.mobile}}</view>
					<view v-else style="#424242">{{maskedPhone}}</view>
				</view>
				<u-line></u-line>
				<view class="userinfo_center_buttom">
					<view class="userinfo_center_buttom_item">
						<text class="userlefttext">{{userinfo.nationStr==null?'未知':userinfo.nationStr}}</text>
						<text class="userrighttext">民族</text>
					</view>
					<view class="userinfo_center_buttom_item">
						<text class="userlefttext">{{userinfo.cityStr==null?'未知':userinfo.cityStr}}</text>
						<text class="userrighttext">户籍地</text>
					</view>
					<view class="userinfo_center_buttom_item">
						<text class="userlefttext">{{userinfo.birthDate==null?'未知':userinfo.birthDate}}</text>
						<text class="userrighttext">出身年份</text>
					</view>
					<view class="userinfo_center_buttom_item">
						<text class="userlefttext">{{userinfo.degreeStr==null?'未知':userinfo.degreeStr}}</text>
						<text class="userrighttext">最高学历</text>
					</view>
				</view>
			</view>
		</view>
		<view class="job">
			<view class="job_title">
				<text>想要的工作</text>
				<view class="" @click="gotoJob()">
					<u-icon v-if="type==1" class="" label="编辑工作资料" name="arrow-right" size="18" label-pos="left"
						space="5"></u-icon>
				</view>
			</view>
			<view class="job_center">
				<view class="job_center_item">
					<view class="userlefttext">想去的城市</view>
					<view style="color: #0575FF;">{{userinfo.hopeAddr==null?'未知':userinfo.hopeAddr}}</view>
				</view>
				<u-line></u-line>
				<view class="job_center_item">
					<view class="userlefttext">想做的工作</view>
					<view style="color: #0575FF;">{{userinfo.skills==null?'未知':userinfo.skills}}</view>
				</view>
				<u-line></u-line>
				<view class="job_center_item">
					<view class="userlefttext">期望工资</view>
					<view style="color: #0575FF;">{{getMoeny()}}</view>
				</view>
				<u-line></u-line>
				<view class="job_center_item" v-if="userinfo.labelsStr">
					<view class="userlefttext">福利要求</view>
					<view style="color: #0575FF;">{{userinfo.labelsStr==null?'未知':userinfo.labelsStr}}</view>
				</view>
				<u-line></u-line>
				<view class="job_center_item">
					<view class="userlefttext">找工作状态</view>
					<view style="color: #0575FF;">{{getJobStatue(userinfo.status)}}</view>
				</view>
			</view>
		</view>
		<view class="job">
			<view class="job_title">
				<text>个人简介</text>
				<view class="" @click="gotoInfo()">
					<u-icon v-if="type==1" class="" label="编辑个人简介" name="arrow-right" size="18" label-pos="left"
						space="5"></u-icon>
				</view>
			</view>
			<view class="job_center">
				<view class="jianjie">
					<text>{{userinfo.notice?userinfo.notice:"暂无"}}</text>
				</view>
			</view>
		</view>
		<view class="job">
			<view class="job_title">
				<text>工作经历</text>
				<view class="" @click="gotoAddJobPage()">
					<u-icon v-if="type==1" class="" label="编辑工作经历" name="arrow-right" size="18" label-pos="left"
						space="5"></u-icon>
				</view>
			</view>
			<view class="job_center">
				<view style="padding: 6px;border-radius: 8px;" v-for="(item,index) in userinfo.productHistoryList">
					<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;">
						<view
							style="display: flex;flex-direction: row;margin: 10px;color: #0F0F0F;font-weight: bold;font-size: 18px;">
							{{item.enterpriseName}}
						</view>
						<text v-if="type==1" style="color: #0575FF;font-size: 14px;" @click="gotoAddJob(item)">修改</text>
					</view>
					<!-- <view style="margin-left: 10px;margin-right: 10px;display: flex;flex-direction: row;">
						<text style="color: #A1A1A1;margin-right: 20px;font-size: 15px;">{{item.startTime}} -
							{{item.endTime}}</text>
						<text style="color: #0F0F0F;font-size: 15px;">{{item.skill}}</text>
					</view> -->
					<view style="display: grid;grid-template-columns:2fr 1fr;">
						<text
							style="color: #A1A1A1;margin-left: 15px;;margin-right: 20px;font-size: 15px;">{{item.startTime}}
							- {{item.endTime}}</text>
						<text style="color: #0F0F0F;font-size: 15px;">{{item.skill}}</text>
					</view>
					<view style="color: #424242;font-size: 15px;margin: 10px;">
						{{item.remark}}
					</view>
					<u-line></u-line>
				</view>
			</view>
		</view>
		<view class="job" v-if="type==1">
			<view class="job_title">
				<text>技能证书</text>
				<view class="" @click="gotozhengshu()">
					<u-icon v-if="type==1" class="" label="添加证书" name="arrow-right" size="18" label-pos="left"
						space="5"></u-icon>
				</view>
			</view>
			<view class="job_center">
				<view class="tag_container">
					<zyTag :img="img" ref="zyAddTag" v-for="(item,index) in getTagList(userinfo.certificateInfoList)"
						:text="item" closable @delete="deleteTag(item)" />
				</view>
			</view>
		</view>
		<view class="job" v-if="type==0&&userinfo.certificateInfoList&&userinfo.certificateInfoList.length>0">
			<view class="job_title">
				<text>技能证书</text>
				<view class="">
					<!-- <u-icon v-if="type==1" class="" label="添加证书" name="arrow-right" size="18" label-pos="left" space="5"></u-icon> -->
				</view>
			</view>
			<view class="job_center">
				<view class="tag_container">
					<zyTag :closable="true" ref="zyAddTag"
						v-for="(item,index) in getTagList(userinfo.certificateInfoList)" :text="item" addible />
				</view>
			</view>
		</view>
		<view v-if="type == 0" style="height: 130rpx;"></view>
		<view class="tool_bottom" v-if="type == 0">
			<view class="tool_bottom">
				<view class="fabuview">
					<button class="callbtn" @click="callphone()">电话联系</button>
				</view>
			</view>
		</view>
		<u-modal :show="showrelease" content='您暂无招工发布,请先发布招工信息' @confirm="gorelease" @close="closerelease"
				:closeOnClickOverlay="true" ></u-modal>
	</view>
</template>

<script>
	import zyTag from '../../components/zy-tag/zy-tag.vue'
	import Index from "@/common/index-model.js"
	import pop from "@/components/ming-pop/ming-map.vue"
	import fun from "@/common/publicFun.js"
	let index = new Index()
	let that = null
	export default {
		data() {
			return {
				item: "编辑个人资料",
				userinfo: {},
				uid: 0,
				type: 0, //1个人中心进入需要编辑 其他地方进入无需编辑
				img: require('@/static/ming-pop/close.png'),
				ordernumber:'',
				showrelease:false,
				phonenum:'',
				entid:''
			}
		},
		components: {
			pop,
			zyTag
		},
		computed: {
			maskedPhone() {
				if (!this.userinfo.mobile || this.userinfo.mobile.length < 7) return "";
				// 保留前3位 + 4个星号 + 后4位（适用于11位手机号）
				return (
					this.userinfo.mobile.substring(0, 3) +
					"****" +
					this.userinfo.mobile.substring(7)
				);
			}
		},
		methods: {
			//通用跳转
			NavUrlRd(url) {
				if (uni.getStorageSync('token')) {
					index.navigate_to(url)
				} else {
					uni.navigateTo({
						url: "/pagesC/login/login"
					});
				}
			},
			closeNotimestip() {
				this.showNotimes = false
			},
			govip(code) {
				this.showNotimes = false
				let uid = uni.getStorageSync('userid')
				this.NavUrlRd('/pagesB/rechargeVip/rechargeVip?userId=' + uid + '&&entid=' + this.entid + '&&code=' + code)
			},
			gorelease(){
				this.showrelease = false
				uni.redirectTo({
					url: "/pagesC/job/issuejob?&entid=" + this.entid
				});
			},
			closerelease(){
				this.showrelease = false
			},
			callphone() {
				if (uni.getStorageSync('token')) {
					if(this.ordernumber == 0){
						this.showrelease = true
						return
					}
					console.log('可以联系了')
					this.getphonenum(this.userinfo.userId)
				}else {
					index.navigate_to('../../pagesC/login/login');
				}
			},
			getphonenum(id) {
				console.log(id)
				let url = '/client/card/contract/' + id
				index.getPublicUserMember({}, url, 'get', res => {
					if (res.data.code == 200 && res.data.success) {
						console.log('请求电话号', res.data.result)
						this.phonenum = res.data.result
						this.playtel()
					} else if (res.data.code == 503 ||res.data.code == 504) {
						console.log('无次数')
						let code = res.data.code?res.data.code:''
						uni.showModal({
							content: res.data.message,
							// content: '今日可用次数已用完，可前往app充值',
							confirmText: '确认',
							cancelText: '取消',
							  success: (res) => {
							    if (res.confirm) {
							      this.govip(code);
							    } else {
							      this.closeNotimestip();
							    }
							  }
						})
					} else {
						console.log('请求电话号失败', res)
					}
				})
			},
			playtel() {
				if (uni.getStorageSync('token')) {
					if (this.userinfo.userId == uni.getStorageSync('userid')) {
						uni.showToast({
							title: '不能联系自己',
							icon: 'none'
						})
					} else {
						uni.makePhoneCall({
							phoneNumber: this.phonenum,
							// phoneNumber: item.contractMobile,
							success: function() {
								let data = {
									userId: this.userinfo?this.userinfo.userId:'',
								}
								console.log('打电话时请求的数据是：', data);
								index.getPublicUserMember(data, 'client/contact/phone/callPhone', 'post',
									res => {
										console.log('添加拨打电话记录成功！');
									})
							},
							fail: function() {
								console.log('拨打电话失败！');
							}
						});
					}
				} else {
					index.navigate_to('../../pagesC/login/login');
				}
			},
			//删除标签
			deleteTag(item) {

				let id = ''
				this.userinfo.certificateInfoList.forEach((v, i) => {
					if (v.cname == item) {
						id = v.id
					}
				})
				console.log('删除标签', item, id)
				index.getPublicUserMember({}, '/client/card/delCert/' + id, 'post', res => {
					console.log('删除成功', res)
					this.getUserInfo()

				})
			},
			getJobStatue(status) {
				let str = ""
				if (status == 0) {
					str = "找活中"
				} else if (status == 1) {
					str = "暂不找活"
				} else {
					str = "有活考虑新工作"
				}
				return str
			},
			getMoeny() {
				if (this.userinfo.salary) {
					return this.userinfo.salary + ' - ' + this.userinfo.salaryMax + '元'
				} else {
					return '未填写'
				}
			},
			getTagList(data) {
				let list = []
				data.forEach((v, i) => {
					list.push(v.cname)
				})
				console.log('证书列表是', list)
				return list
			},
			gotozhengshu() {
				uni.navigateTo({
					url: "/pagesB/perfectWork/certificate"
				})
			},
			gotoAddJob(item) {
				uni.navigateTo({
					url: "/pagesB/perfectWork/experience?id=" + item.id
				})
			},
			gotoAddJobPage() {
				uni.navigateTo({
					url: "/pagesB/perfectWork/experience"
				})
			},
			gotoInfo() {
				let data = this.userinfo
				uni.navigateTo({
					url: "/pagesB/perfectWork/introduce?data=" + JSON.stringify(data)
				})
			},
			getUserInfo() {
				// index.getPublicUserMember({}, '/client/individual/homePage', 'get', res => {
				// 		this.userinfo = res.data.result;
				// 		console.log('获取的个人信息是',this.userinfo)
				// })
				// let uid = uni.getStorageSync('userid')
				console.log('当前登录的用户id是', this.uid)
				index.getPublicUserMember({
					"uid": this.uid
				}, '/client/card/detailNoAudit', 'get', res => {
					this.userinfo = res.data.result;
					console.log('获取的个人信息是', this.userinfo)
				})
			},
			// getUserInfo1() {
			// 	index.getPublicUserMember({}, 'client/individual/select/information', 'post', res => {
			// 		if (res.data.code == 200 && res.data.success) {
			// 			console.log('查电话',res.data.result)
			// 			this.usermobile = res.data.result.mobile
			// 		}
			// 	})	
			// },
			gotoUser() {
				let data = this.userinfo
				console.log('传递的个人信息是', data)
				uni.navigateTo({
					url: "/pagesC/edituserInfo/edituserInfo?data=" + JSON.stringify(data)
				})
			},
			gotoJob() {
				let data = this.userinfo
				console.log('传递的个人信息是', data)
				uni.navigateTo({
					url: "/pagesC/editJobinfo/editJobinfo?data=" + JSON.stringify(data)
				})
			}
		},
		onLoad(opt) {
			// this.maxDate = date.getTime();
			this.uid = opt.userId
			this.type = opt.type
			this.ordernumber = opt.ordernumber
			this.entid = opt.entid
			console.log("传传传参",this.entid)
		},
		onShow() {
			// if (uni.getStorageSync("phone")) {
			// 	this.FormData.mobile = uni.getStorageSync("phone");
			// }
			this.getUserInfo();
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F6F6;
	}

	.tag_container {
		display: flex;
		align-items: center;
		flex-direction: row;
		flex-wrap: wrap;
		padding: 10px;
	}

	.job {
		display: flex;
		flex-direction: column;

		.job_title {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			margin-left: 15px;
			margin-right: 15px;
		}
	}

	.job_center {
		display: flex;
		flex-direction: column;
		margin: 15px;
		background-color: white;
		border-radius: 8px;
		// text-align: center;

		.job_center_item {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			margin: 6px;
			// height: auto;
			text-align: center;
			align-items: center;
			height: 40px;
		}

		.jianjie {
			margin: 6px;
			height: auto;
		}
	}

	.userlefttext {
		color: #424242;
		font-size: 14px;
		font-family: PingFang SC;
		font-weight: 400;
	}

	.userrighttext {
		color: #A1A1A1;
		font-size: 12px;
		font-family: PingFang SC;
		font-weight: 400;
	}

	.user {
		display: flex;
		flex-direction: column;

		.userinfo_center {
			display: flex;
			flex-direction: column;
			margin: 15px;
			background-color: white;
			border-radius: 8px;

			.userinfo_center_item {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				margin: 6px;
				height: 40px;
				align-items: center;
			}

			.userinfo_center_buttom {
				display: grid;
				grid-template-columns: repeat(4, 1fr);
				height: 50px;

				.userinfo_center_buttom_item {
					display: flex;
					flex-direction: column;
					text-align: center;
					align-items: center;
				}
			}
		}
	}

	.userinfo {
		display: flex;
		flex-direction: row;
		height: 60px;
		width: 100%;
		text-align: center;

		.userinfo_top {
			height: 100%;
			width: 50%;
			display: flex;
			flex-direction: row;
			text-align: center;
			align-items: center;
			padding-left: 15px;

			.userinfo_top_img {
				width: 45px;
				height: 45px;
				margin-right: 10px;
			}
		}

		.userinfo_top_right {
			height: 100%;
			width: 50%;
			display: flex;
			flex-direction: row;
			justify-content: flex-end;
			padding-right: 15px;
		}
	}
	.tool_bottom {
		width: 100%;
		padding: 10px;
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-top: 1px solid #e3e3e3;
		background-color: #f0f0f0;
		height: 50px;
	
		.fabuview {
			height: 45px;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 3px;
			background-color: #0575FF;
			width: 100%;
			margin-right: 20px;
	
			.callbtn {
				padding: 10rpx;
				// height: 45px;
				width: 100%;
				text-align: center;
				color: #fff;
				background: #0575ff;
				font-size: 16px;
				border: none;
				box-shadow: none;
				border-width: 0px;
				box-sizing: border-box;
			}
		}
	
	}
</style>